package us.icitap.cm.business.entities;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.eclipse.persistence.annotations.Customizer;

import us.icitap.cm.utils.MyCustomizer;

@Entity
@Customizer(MyCustomizer.class)
@Table(name="POLICE_CODE", schema="MPC")
public class PoliceCode implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = -8128986209324583659L;

	@Id
	@Column(length=4)
	private String code;
	
	@Column(length=150)
	private String tag;
	
	@ManyToOne
	@JoinColumn(name="SUPERIOR_ID")
	private PoliceCode superiorPoliceCode;
	
	@OneToMany(mappedBy="superiorPoliceCode")
	private List<PoliceCode> childrenPoliceCode;
	
	@ManyToOne(cascade=CascadeType.PERSIST)
	@JoinColumn(name="PENAL_CODE_ID")
	private PenalCode penalCode;
	private boolean status = true;
	
	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getTag() {
		return tag;
	}

	public void setTag(String tag) {
		this.tag = tag;
	}

	public PoliceCode getSuperiorPoliceCode() {
		return superiorPoliceCode;
	}

	public void setSuperiorPoliceCode(PoliceCode superiorPoliceCode) {
		this.superiorPoliceCode = superiorPoliceCode;
	}

	public PenalCode getPenalCode() {
		return penalCode;
	}

	public void setPenalCode(PenalCode penalCode) {
		this.penalCode = penalCode;
	}

	public boolean isStatus() {
		return status;
	}

	public void setStatus(boolean status) {
		this.status = status;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((code == null) ? 0 : code.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		PoliceCode other = (PoliceCode) obj;
		if (code == null) {
			if (other.code != null)
				return false;
		} else if (!code.equals(other.code))
			return false;
		return true;
	}

	public List<PoliceCode> getChildrenPoliceCode() {
		return childrenPoliceCode;
	}

	public void setChildrenPoliceCode(List<PoliceCode> childrenPoliceCode) {
		this.childrenPoliceCode = childrenPoliceCode;
	}

	@Override
	public String toString() {
		return code +" - "+ tag;
	}
}
